$(function(){
	$('#menu1').datalist({
		fit: true,
        lines: true,
        border: false,
        textFormatter: function(value){
            return '<a class="datalist-link">' + value + '</a>';
        },
        onClickRow: function(index,row){
            $('#p2-title').html(row.text);
            initp2pn(index);
        }
	});
});

function initmain(){
	$('#p2-pn').html('');
	$.mobile.go('#main','slide','right');
}

function initp2pn(index){
	$('#p2-pn').html('');
	$('#p2-pn').panel({fit:true,border:false});
    var htmls = ['madd.html','mrepost.html','mchart.html'];
	$('#p2-pn').panel('refresh',htmls[index]);
    $.mobile.go('#p2','slide','left');
}

function submit(){
	var keys = ["Alias","Accepted","Vender","Dept","Location","LonLat","Project","isInTYGJ","is2750","Comments"];
	var json = {};
	for(var i=0;i<keys.length;i++){
		var str = $('#v_'+keys[i]).val();
		if(null!=str && str.length>0) {
			if(i==5) {
				json['Lon'] = gpsvalue.lon;
				json['Lat'] = gpsvalue.lat;
			}else if(i==1 ||i==7 ||i==8){
				if(str=='on') json[keys[i]] = "是";
				else json[keys[i]] = "否";
			}else json[keys[i]] = str;
		}else json[keys[i]] = "";
	}
	$.post("/Distribution/site",{ add: JSON.stringify(json) }, function(data) {
		$.messager.alert('','站点信息已保存。');
	});
}

function getlist(){
	if($('#v_datestart').combobox('getValue').length==0){
		$.messager.alert('','开始时间未选择');
		return;
	}
	if($('#v_datestart').combobox('getValue').length==0){
		$.messager.alert('','结束时间未选择');
		return;
	}
	if($('#v_me').combobox('getValue').length==0){
		$.messager.alert('','查询网元未选择');
		return;
	}
	var alarmtype;
	if($('#v_me').combobox('getValue').indexOf('systemid')>-1) alarmtype = '3G';
	else alarmtype = '4G';
	$.post("/Distribution/cfg",{ 
		alarm : alarmtype,
		mo : $('#v_me').combobox('getValue'),
		datestart : $('#v_datestart').combobox('getValue'),
		dateend : $('#v_dateend').combobox('getValue') 
		},function(list) {
			console.log(list);
			$('#getdetail').datagrid({
			    data:list,
			    columns:[[
					        {field:'date',title:'告警时间',align:'center',sortable:true},
					        {field:'reason',title:'原因',align:'center',sortable:true},
							{field:'description',title:'描述',align:'left',sortable:true}
					    ]],
				fitColumns:true,
				fit:true,
			    singleSelect:true,
			    collapsible:true,
			    multiSort:true,
			    pagination:false
			});
	});
}

function getchart(){
	$('#rssi').height($('#p2-pn').height()-120);
	$.post("/Distribution/cfg",{ 
		rssi: $('#v_me').combobox('getValue'),
		datestart:$('#v_datestart').textbox('getValue'),
		dateend:$('#v_dateend').textbox('getValue') 
	},function(list) {
		var data = convertSeriesRSSI(list);
		var chart = echarts.init(document.getElementById('rssi'));
        var option = {
    	    tooltip: {
    	        trigger: 'axis'
    	    },
    	    legend: {
    	        data:data.name
    	    },
    	    dataZoom: [{show: true,realtime: true,xAxisIndex: 0}],
    	    xAxis:  {
    	        type: 'category',
    	        boundaryGap: false,
    	        data: data.time
    	    },
    	    yAxis: {
    	        type: 'value',
    	        min:'dataMin',
    	        max:'dataMax',
    	        showMinLabel:true,
    	        showMaxLabel:true,
    	        axisLabel: {
    	            formatter: '{value}'
    	        }
    	    },
    	    series: data.rssi
    	};
        chart.setOption(option);
	});
}
